﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Web.Services;

public partial class collectionDetailPage : System.Web.UI.Page
{
    CommonPage _comment = new CommonPage();
    VLGDataContext _dataContext = new VLGDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["currentItem"] = "yoursp";
        if (!IsPostBack)
        {
            Page.Title = "Trang cá nhân | Bộ sưu tập của bạn";
            try
            {
                if (String.IsNullOrEmpty(Session["KhachHang"].ToString()))
                {
                    Response.Redirect(ResolveClientUrl("warnLogin.aspx"));
                }
                else
                {
                    fillDulieuLenGrid();
                }
            }
            catch { Response.Redirect(ResolveClientUrl("Default.aspx")); }
        }
    }
    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
        fillDulieuLenGrid();
    }
    void fillDulieuLenGrid()
    {
        
       
        if (Request.QueryString["idCollection"] != null)
        {
            var collectionDetail = from cd in _dataContext.CollectionDetails
                                   where cd.idCollection == Convert.ToInt32(Request.QueryString["idCollection"])
                                   select cd;
            AspNetPager1.RecordCount = collectionDetail.Count();
            rptCollectionDetail.DataSource = collectionDetail.Skip(AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1)).Take(AspNetPager1.PageSize);
            rptCollectionDetail.DataBind();
        }
    }

    protected void btnTiep2_Click(object sender, EventArgs e)
    {
        string noidung = TextBox1.Text.ToString().Trim();
        Response.Redirect(ResolveClientUrl("~/qlcongviec.aspx?op=add&to=") + noidung);
    }
    [WebMethod]
    public static int DeleteCollectionDetail(string idCollectionDetail)
    {

        if (!string.IsNullOrEmpty(idCollectionDetail))
        {
            try
            {
                VLGDataContext _dataContext = new VLGDataContext();
                CommonPage _comment = new CommonPage();
                var idInt = Convert.ToInt32(idCollectionDetail);
                var collectionDetail = _dataContext.CollectionDetails.Select(p => p).Where(p => p.idCollectiondDetail == idInt);
                _dataContext.CollectionDetails.DeleteAllOnSubmit(collectionDetail);             
                _dataContext.SubmitChanges();
                return 1;
            }
            catch
            {

                return 0;
            }

        }
        else return 0;
    }
}